﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;

public static class UnityEngineExtend  {




    public static GameObject CreateLocalChild(this GameObject obj, GameObject prefab)
    {
        GameObject go = null;
        if(prefab != null)
        {
            go = GameObject.Instantiate(prefab);
            go.name = prefab.name;
            _SetDefaultTransform(go, obj.transform);
        }
        return go;
    }


    public static GameObject CreateLocalEmptyChild(this GameObject obj,string name)
    {
        GameObject go = new GameObject(name);
        if(obj.GetComponent<RectTransform>() != null)
        {
            var rectTransform = go.AddComponent<RectTransform>();
            rectTransform.anchoredPosition3D = Vector3.zero;
            rectTransform.sizeDelta = new Vector2(0, 0);
        }
        _SetDefaultTransform(go, obj.transform);
        return go;
    }

    private static void _SetDefaultTransform(GameObject obj,Transform parent)
    {
        obj.transform.SetParent(parent);
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale = Vector3.one;
        obj.transform.localRotation = Quaternion.identity;
    }

    public static void Info(this GameObject obj,string log)
    {
       // GameObject go = obj as GameObject;
        Loger.Info(log,obj.name);
    }

    public static void Waring(this GameObject obj, string log)
    {
        GameObject go = obj as GameObject;
        Loger.Warring(log, obj.name);
    }

    public static void Error(this GameObject obj, string log)
    {
        GameObject go = obj as GameObject;
        Loger.Error(log, obj.name);
    }

    public static void Special(this GameObject obj, string log)
    {
        GameObject go = obj as GameObject;
        Loger.Special(log, obj.name);
    }
}